package com.yxkj.syh.app.huarong.activities.user.setting;

import android.app.Application;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.alibaba.android.arouter.launcher.ARouter;
import com.syh.app.basic.base.BaseResponse;
import com.syh.app.basic.base.view_model.BaseViewModel;
import com.syh.app.basic.bindingAdp.view_click.ClickEvent;
import com.syh.app.basic.utils.Tooast;
import com.syh.app.basic.utils.net.ApiObserver;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.yxkj.syh.app.huarong.constants.ArouterPath;
import com.yxkj.syh.app.huarong.data_center.model.AuthModel;

/**
 * 创建者：SYH
 * 时间：2020/5/21 9:25
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class SettingVM extends BaseViewModel<ActivityEvent> {

    public SettingVM(@NonNull Application application) {
        super(application);
    }

    public MutableLiveData<Boolean> mldLogin = new MutableLiveData<>();


    public ClickEvent logoutClick = new ClickEvent() {
        @Override
        public void onClick(View view) {
            logout();
        }
    };
    public ClickEvent pwdClick = new ClickEvent() {
        @Override
        public void onClick(View view) {
            ARouter.getInstance().build(ArouterPath.EDIT_PWD_ACTIVITY).navigation();
        }
    };


    public void logout(){
        AuthModel.getAuthModel().logout(mLifecycleProvider.bindToLifecycle(), new ApiObserver<BaseResponse>() {
            @Override
            public void onSuccess(BaseResponse response) {
                mldLogin.setValue(true);
            }

            @Override
            public void onFailed(int code, String msg) {
                mldLogin.setValue(true);
                Tooast.warning(msg);
            }
        });
    }
}
